package com.nd.mobile.study.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Environment;

import com.nd.mobile.study.common.App;
import com.nd.mobile.study.common.BaseActivity;
import com.nd.mobile.study.common.constants.BundleConstants;
import com.nd.mobile.study.view.helper.ToastHelper;

public class VitamioInstallerUtil {

	private static final String URL_PATTERN = "http://yddd.91pgy.com/vitamio/vitamio%s.apk";
	
	private VitamioInstallerUtil() {}

	private static HashMap<String, String> map;
	
//	public static HashMap<String, String> initSource() {
//		if (null == map) {
//			map = new HashMap<String, String>();
//			map.put(VitamioInstaller.VITAMIO_PACKAGE_ARMV6, String.format(URL_PATTERN, 60));
//			map.put(VitamioInstaller.VITAMIO_PACKAGE_ARMV6_VFP, String.format(URL_PATTERN, 61));
//			map.put(VitamioInstaller.VITAMIO_PACKAGE_ARMV7_VFPV3, String.format(URL_PATTERN, 70));
//			map.put(VitamioInstaller.VITAMIO_PACKAGE_ARMV7_NEON, String.format(URL_PATTERN, 71));
//		}
//		return map;
//	}

	public static boolean check(final Context context) {
		return true;
//		boolean result = false;
//		try {
//			String pkgName = VitamioInstaller.checkVitamioInstallation(App.getInstance());
//			L.v("pkgName", pkgName);
//			if (null != pkgName) {
//				result = true;
//			}
//		} catch (VitamioNotCompatibleException e) {
//			ToastHelper.displayToastLong(App.getInstance(), "本应用的视频播放暂不兼容您的手机");
//			e.printStackTrace();
//		} catch (VitamioNotFoundException e) {
//			if (!AppInstallService.isDownloading()) {
//				Builder builder = new AlertDialog.Builder(context);
//				builder
//				.setTitle("视频播放插件未安装")
//				.setMessage("检测到您的手机还未安装视频播放插件,是否立即安装?\n(插件大小根据不同手机约为3~4MB)")
//				.setPositiveButton("安装", new Dialog.OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						String CompatiblePkgName = VitamioInstaller.getCompatiblePackage();
//						String apkPath = initSource().get(CompatiblePkgName);
//						Intent intent = new Intent();
//						intent.setClass(context, AppInstallService.class);
//						intent.putExtra(BundleConstants.VITAMIO_APK_URL, apkPath);
//						context.startService(intent);
//					}
//				})
//				.setNegativeButton("取消", null).create().show();
//			}else{
//				ToastHelper.displayToastLong(App.getInstance(), "视频播放插件正在下载中");
//			}
//			e.printStackTrace();
//		} catch (Exception e) {
//			L.v("errorMsg", e.getMessage());
//			e.printStackTrace();
//		}
//		return result;
	}
	
}
